// app 页面接口
const express = require('express')
const writeData = require('../../db/module/writeData')
const readData = require('../../db/module/readData')
const delData = require('../../db/module/delData')
const apiRouter = express.Router()

// 添加or修改 角色
apiRouter.post('/addRole', async (req, res) => {
  try {
    const params = req.body

    let result = await writeData(params, 'role')

    res.send(result)
  } catch (error) {
    res.send({
      code: 50000,
      msg: error
    })
  }
})

// 查询角色
apiRouter.post('/queryRole', async (req, res) => {
  try {
    const params = req.body

    let result = await readData(params, 'role')

    res.send({
      code: 20000,
      data: result.data || [],
      msg: '查询成功'
    })
  } catch (error) {
    res.send({
      code: 50000,
      msg: error
    })
  }
})

// 删除角色
apiRouter.post('/delRole', async (req, res) => {
  try {
    const params = req.body

    let result = await delData(params, 'role')

    res.send(result)
  } catch (error) {
    res.send({
      code: 50000,
      msg: error
    })
  }
})

module.exports = apiRouter
